<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./axios.min.js"></script>
</head>

<body>
    <script>

        /* 请求拦截 */
        // Add a request interceptor
        axios.interceptors.request.use(function (config) {
           // console.log(config, 777);
            config.headers.token='666666'
            return config;
        }, function (error) {
            // Do something with request error
            return Promise.reject(error);
        });

        // Add a response interceptor
        axios.interceptors.response.use(function (response) {
            console.log(response,888888);
            
            // Do something with response data
            return response.data;
        }, function (error) {
            // Do something with response error
            return Promise.reject(error);
        });

        /* 配置公共地址 */
        axios.defaults.baseURL = 'http://127.0.0.1:3000/';
        axios.defaults.headers.common['Authorization'] = 'AUTH_TOKEN';
        axios.get('/fdata').then(res => {
            console.log(res, 123);
        })
        axios.get('books/555').then(res => {
            console.log(res, 456);

        })

        /* axios传参有坑====== */
        // axios('http://127.0.0.1:3000/books',{params:{id:33}}).then(res=>{
        //     console.log(res,11111);
        // })

        // axios.post('http://127.0.0.1:3000/books',{uname:'admin',pwd:'123456'}).then(res=>{
        //     console.log(res,22222);
        // })


        /* async  +   await   */
        // async function  aa(){
        //     var {data:res}=await axios.post('http://127.0.0.1:3000/books',{uname:'admin',pwd:'44444'})
        //     console.log(res,333);

        // }
        // aa()



        // axios('http://127.0.0.1:3000/books/22').then(res=>{
        //     console.log(res,11111);
        // })





    </script>
</body>

</html>